<?php

namespace App\Admin\Controllers;

use App\Models\User;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;
use Encore\Admin\Facades\Admin;

class UsersController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('用户列表')
           // ->description('description')
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed   $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('Detail')
            ->description('description')
            ->body($this->detail($id));
    }


    protected function grid()
    {

        return Admin::grid(User::class,function (Grid $grid){

            $grid->id('ID')->sortable();
            $grid->name('用户名');
            $grid->email('邮箱');
//            $grid->password('Password');
            //$grid->remember_token('Remember token');
            $grid->email_verified('已验证邮箱')->display(function ($value){
                return $value ? '是' : '否';
            });
            $grid->created_at('注册时间');
            //不显示新建按钮
            $grid->disableCreateButton();

            $grid->actions(function ($actions){
                //不显示查看按钮
                $actions->disableView();

                //不显示删除按钮
                $actions->disableDelete();

                //不显示编辑按钮
                $actions->disableEdit();
            });

            $grid->tools(function ($tools){
                //急用批量删除

                $tools->batch(function ($batch){
                    $batch->disableDelete();
                });
            });
        });




    }

    /**
     * Make a show builder.
     *
     * @param mixed   $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(User::findOrFail($id));

        $show->id('Id');
        $show->name('Name');
        $show->email('Email');
        $show->password('Password');
        $show->remember_token('Remember token');
        $show->email_verified('Email verified');
        $show->created_at('Created at');
        $show->updated_at('Updated at');

        return $show;
    }


}
